<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class BaseModel extends Model
{
    //
    use SoftDeletes;

    protected static $attribute_switch = true;

    protected static $close_appends = [];

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);
        if(self::$attribute_switch){
            $this->appends = array_values(array_diff($this->appends, self::$close_appends));
        }else{
            $this->appends = [];
        }
    }

    /**
     * User: Virus
     * DateTime: 2021/6/22 10:47
     * Describe: 关闭模型的所有 Appends 获取器
     * Version:
     * @param boolean $value
     */
    public static function setAttributeSwitch(bool $value)
    {
        self::$attribute_switch = $value;
    }

    /**
     * User: Virus
     * DateTime: 2021/6/22 11:03
     * Describe: 关闭模型的指定 Appends 获取器
     * Version:
     * @param array $columns
     */
    public static function closeAttributeSwitch(array $columns)
    {
        self::$close_appends = $columns;
    }
}
